#include<iostream>
#define gua(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
int n;
int a[35];
int dp[35][35];
int fa[35][35];
int dfs(int l,int r){
	if(dp[l][r])return dp[l][r];
	if(l==r+1)return dp[l][r]=1;
	if(l==r)return dp[l][r]=a[l];
	gua(i,l,r){
		int p=dfs(l,i-1)*dfs(i+1,r)+a[i];
		if(p>dp[l][r]){
			dp[l][r]=p;
			fa[l][r]=i;
		}
	}
	return dp[l][r];
}
void gg(int l,int r){
	if(r<l)return;
	if(l==r){
		cout<<l<<' ';
		return;
	}
	cout<<fa[l][r]<<' ';
	gg(l,fa[l][r]-1);
	gg(fa[l][r]+1,r);
}
int main(){
	cin>>n;
	gua(i,1,n)cin>>a[i];
	dp[1][n]=dfs(1,n);
	cout<<dp[1][n]<<endl;
	gg(1,n);
	return 0;
}
